package com.example.doc.controller;

import com.example.doc.model.RespBean;
import com.example.doc.model.Role;
import com.example.doc.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    RoleService roleService;

    @GetMapping
    public List<Role> getAllRoles(){
        return roleService.getAllRoles();
    }

    @PostMapping("/add")
    public RespBean addRole(@RequestBody Role role){
        if (roleService.saveRole(role) == 1){
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

//    @PutMapping("/edit")
//    public RespBean editRole(@RequestBody Role role){
//
//    }

    @DeleteMapping("/delete/{id}")
    public RespBean deleteRole(@PathVariable Long id){
        if (roleService.deleteRole(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }


}
